var http = require('http');
var querystring = require("querystring");
var fs = require("fs");
var pack = require("./pack");

http.createServer(function(request, response) {
    var post_data = "";

    request.setEncoding('utf8');
    request.addListener('data', function(data) {
        post_data += data;
    })
    request.addListener('end', function () {
        var param = querystring.parse(post_data);
        var projectpath = param.path;
        //console.log(projectpath)

        pack(projectpath, projectpath + "/output.wx").then(function (value) {
            response.writeHead(200, {'Content-Type': 'text/html'});
            if (value) {
                response.write(value.data);
                response.end();
            } else {
                response.write("1");
                response.end();
            }
        }).catch(function (e) {
            response.write("1");
            response.end();
        })
    })
}).listen(9912, "127.0.0.1");

